package com.authine.cloudpivot.ext.applicationservice;

import cn.hutool.json.JSONUtil;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.dao.QuotationGoods;
import com.authine.cloudpivot.ext.dao.VendorGoodsMatchedInquiryGoods;
import com.authine.cloudpivot.ext.dao.VendorGoodsMatchedQuotation;
import com.authine.cloudpivot.ext.dto.VendorGoodsMatchedDto;
import com.authine.cloudpivot.ext.dto.inquiry.CreateInquiryDto;
import com.authine.cloudpivot.ext.dto.inquiry.CreateInquiryGoodsDto;
import com.authine.cloudpivot.ext.dto.inquiry.InquiryGoodsDto;
import com.authine.cloudpivot.ext.dto.quotation.QuotationGoodsDto;
import com.authine.cloudpivot.ext.dto.system.OrganizationDto;
import com.authine.cloudpivot.ext.enums.goods.GoodsType;
import com.authine.cloudpivot.ext.enums.inquiry.QuotationSourceEnum;
import com.authine.cloudpivot.ext.exception.InquiryException;
import com.authine.cloudpivot.ext.utils.BigDecimalUtils;
import com.authine.cloudpivot.ext.utils.BoResultFormat;
import com.authine.cloudpivot.ext.utils.BoServiceUtils;
import com.authine.cloudpivot.ext.utils.JdbcTemplateUtils;
import com.authine.cloudpivot.ext.utils.system.BeanUtils;
import com.authine.cloudpivot.ext.utils.system.OrgUtils;
import com.authine.common.util.DateUtils;
import com.authine.hermes.app.launcher.service.ApplicationService;
import com.authine.mvp.app.launcher.common.SchemaHelper;
import com.authine.mvp.app.launcher.domain.AttachmentFormat;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.response.BO;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Sets;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @ClassName VendorGoodsMatchedQuotationService
 * @Description: 平台报价匹配
 * @Author fj
 * @Date 2021/6/7
 * @Version V1.0
 **/
@Path("VendorGoodsMatchedQuotationService")
@Slf4j
public class VendorGoodsMatchedQuotationService extends ApplicationService {
    private static final QuotationService quotationService = new QuotationService();
    private static final NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);

    /**
     * 根据询价商品(型号)查询供应商商品生成预报价商品列表
     *
     * @param inquiryGoodsList 询价商品列表
     * @param statusMap        是否自动匹配状态
     */
    @Path("generateQuotationListByInquiryGoods")
    @POST
    @Operation(summary = "根据询价商品(型号)查询供应商商品生成预报价商品列表", tags = CUSTOM_SERVICE)
    public void generateQuotationListByInquiryGoods(List<CreateInquiryGoodsDto> inquiryGoodsList, Map<String, Boolean> statusMap, boolean created) {
        Set<VendorGoodsMatchedInquiryGoods> inquiryGoodsSet = Sets.newHashSet();
        Set<VendorGoodsMatchedQuotation> quotationGoodsSet = Sets.newHashSet();
        //1、查出所有的询价商品列表
        log.debug("客户询价队列：{}条数据正在进行检索供应商型号。", inquiryGoodsList.size());
        List<Map<String, Object>> inquiryGoodsListData = Lists.newArrayList();
        inquiryGoodsList.forEach(inquiryGoods -> {
            Map<String, Object> inquiryGoodsMapData = Maps.newHashMap();
            Collection<Map<String, Object>> goodsCollection = getGoodsCollection(inquiryGoods);
            if (!goodsCollection.isEmpty()) {
                // 实例化有查询结果的询价商品列表
                VendorGoodsMatchedInquiryGoods vendorGoodsMatchedInquiryGoods = formatByInquiryGoods(inquiryGoods);
                // 构建供应商匹配商品对象
                Boolean isAutoMatching = Optional.ofNullable(statusMap).map(map -> map.getOrDefault(inquiryGoods.getId(), true))
                        .orElse(true);
                quotationGoodsSet.addAll(reBuildVendorGoodsMatchedQuotation(inquiryGoods, goodsCollection, vendorGoodsMatchedInquiryGoods.getId()));
                vendorGoodsMatchedInquiryGoods.setIs_auto_matching(isAutoMatching);
                inquiryGoodsSet.add(vendorGoodsMatchedInquiryGoods);
                inquiryGoodsMapData.put("id", inquiryGoods.getId());
                inquiryGoodsMapData.put("is_matching", true);
                inquiryGoodsListData.add(inquiryGoodsMapData);
            }
        });
        if (!inquiryGoodsSet.isEmpty()) {
            List<Map<String, Object>> vendorGoodsMatchedInquiryGoodsData = Lists.newArrayList();
            for (VendorGoodsMatchedInquiryGoods goodsMatchedInquiryGoods : inquiryGoodsSet) {
                // 将javaBean转成bo需要的map
                Map<String, Object> goodsMap = BeanUtils.bean2Map(goodsMatchedInquiryGoods);
                vendorGoodsMatchedInquiryGoodsData.add(goodsMap);
            }
            SingleResponse<BO> vendorGoodsMatchedInquiryGoodsCreateBO = BoServiceUtils.createBo(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, vendorGoodsMatchedInquiryGoodsData);
            log.info("------------------------生成平台报价询价商品成功，返回结果：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsCreateBO));

        }
        if (!quotationGoodsSet.isEmpty()) {
            List<Map<String, Object>> vendorGoodsMatchedQuotationData = Lists.newArrayList();
            for (VendorGoodsMatchedQuotation quotation : quotationGoodsSet) {
                Map<String, Object> quotationMap = BeanUtils.bean2Map(quotation);
                vendorGoodsMatchedQuotationData.add(quotationMap);
            }
            SingleResponse<BO> vendorGoodsMatchedQuotationCreateBO = BoServiceUtils.createBo(ModelConst.T_VENDOR_MATCHED_QUOTATION, vendorGoodsMatchedQuotationData);
            log.info("------------------------生成平台报价预报价成功，返回结果：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationCreateBO));
        }
        // 更新询价商品为已匹配
        if (!inquiryGoodsListData.isEmpty()) {
            SingleResponse<BO> inquiryGoodsUpdateBO = BoServiceUtils.updateMainBo(ModelConst.T_INQUIRY_GOODS, inquiryGoodsListData);
            log.info("------------------------更新询价商品成功，更新后结果：{}------------------------", JSONObject.toJSONString(inquiryGoodsUpdateBO));
        }
    }

    /**
     * 手动添加匹配商品
     *
     * @param inquiryGoodsDto 询价商品
     * @return 响应结果
     */
    @Path("addMatchGoods")
    @POST
    @Operation(summary = "手动添加匹配商品", tags = CUSTOM_SERVICE)
    public SingleResponse<VendorGoodsMatchedInquiryGoods> addMatchGoods(@Parameter InquiryGoodsDto inquiryGoodsDto) {
        if (inquiryGoodsDto.getInquiryGoodsIdList() == null || inquiryGoodsDto.getInquiryGoodsIdList().isEmpty()) {
            return SingleResponse.error("-1", "询价商品id不能为空");
        }
        if (inquiryGoodsDto.getGoodsIdList() == null || inquiryGoodsDto.getGoodsIdList().isEmpty()) {
            return SingleResponse.error("-2", "商品id不能为空");
        }
        String inquiryGoodsId = inquiryGoodsDto.getInquiryGoodsIdList().get(0);
        // 判断该商品是否匹配过
        SingleResponse<BOList> vendorGoodsMatchedInquiryGoodsBOList = BoServiceUtils.findListBySimple(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, "inquiry_goods_id", inquiryGoodsId);
        log.info("------------------------vendorGoodsMatchedInquiryGoodsBOList：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsBOList));

        // 获取询价商品信息
        SingleResponse<BOList> inquiryGoodsBOList = BoServiceUtils.findListBySimple(ModelConst.T_INQUIRY_GOODS, "id", inquiryGoodsId);
        log.info("------------------------inquiryGoodsBOList：{}------------------------", JSONObject.toJSONString(inquiryGoodsBOList));

        CreateInquiryGoodsDto inquiryGoods = JSON.parseObject(JSON.toJSONString(inquiryGoodsBOList.getData().getData().get(0)), CreateInquiryGoodsDto.class);
        // 获取商品信息
        SingleResponse<BOList> goodsBOList = BoServiceUtils.findListByIn(ModelConst.T_GOODSES, "id", inquiryGoodsDto.getGoodsIdList());
        log.info("------------------------goodsBOList：{}------------------------", JSONObject.toJSONString(goodsBOList));

        Collection<Map<String, Object>> goodsCollection = goodsBOList.getData().getData();
        VendorGoodsMatchedInquiryGoods vendorGoodsMatchedInquiryGoods;
        if (vendorGoodsMatchedInquiryGoodsBOList.getData().getTotal() == 0) {
            vendorGoodsMatchedInquiryGoods = buildVendorGoodsMatchedInquiry(inquiryGoods, goodsCollection);
        } else {
            vendorGoodsMatchedInquiryGoods = JSON.parseObject(JSON.toJSONString(vendorGoodsMatchedInquiryGoodsBOList.getData().getData().get(0)), VendorGoodsMatchedInquiryGoods.class);
            Set<VendorGoodsMatchedQuotation> quotationGoodsSet = reBuildVendorGoodsMatchedQuotation(inquiryGoods, goodsCollection, vendorGoodsMatchedInquiryGoods.getId());
            log.info("------------------------quotationGoodsSet：{}------------------------", JSONObject.toJSONString(quotationGoodsSet));

            Set<VendorGoodsMatchedQuotation> quotationGoodsSetResult = vendorGoodsMatchedInquiryGoods.getVendorGoodsMatchingQuotations();
            if (quotationGoodsSetResult == null) {
                quotationGoodsSetResult = Sets.newHashSet();
            }
            quotationGoodsSetResult.addAll(quotationGoodsSet);
            vendorGoodsMatchedInquiryGoods.setVendorGoodsMatchingQuotations(quotationGoodsSetResult);
        }
        log.info("------------------------vendorGoodsMatchedInquiryGoods：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoods));
        return SingleResponse.of(vendorGoodsMatchedInquiryGoods);
    }

    /**
     * 确认添加匹配商品
     *
     * @param inquiryGoodsDto 询价商品
     * @return 响应结果
     */
    @Path("confirmAddMatchGoods")
    @POST
    @Operation(summary = "确认添加匹配商品", tags = CUSTOM_SERVICE)
    public SingleResponse<BO> confirmAddMatchGoods(@Parameter InquiryGoodsDto inquiryGoodsDto) {
        // 获取询价商品报价匹配记录
        String vendorGoodsMatchedInquiryGoodsId = inquiryGoodsDto.getInquiryGoodsIdList().get(0);
        SingleResponse<BOList> vendorGoodsMatchedInquiryGoodsBOList = BoServiceUtils.findListBySimple(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, "id", vendorGoodsMatchedInquiryGoodsId);
        log.info("------------------------vendorGoodsMatchedInquiryGoods：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsBOList));
        if (!vendorGoodsMatchedInquiryGoodsBOList.isSuccess() || vendorGoodsMatchedInquiryGoodsBOList.getData().getTotal() == 0) {
            return SingleResponse.error("-1", String.format("询价商品%s的报价匹配记录不存在", vendorGoodsMatchedInquiryGoodsId));
        }
        // 获取该询价商品匹配过的商品
        SingleResponse<BOList> vendorGoodsMatchedQuotationBOList = BoServiceUtils.findListBySimple(ModelConst.T_VENDOR_MATCHED_QUOTATION, "vendor_matched_inq_goods_id", vendorGoodsMatchedInquiryGoodsId);
        log.info("------------------------vendorGoodsMatchedQuotationBOList：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationBOList));
        if (vendorGoodsMatchedQuotationBOList.getData().getTotal() != 0) {
            try {
                vendorGoodsMatchedQuotationBOList.getData().getData().forEach(vendorGoodsMatchedQuotationMap -> {
                    if (inquiryGoodsDto.getGoodsIdList().contains(String.valueOf(vendorGoodsMatchedQuotationMap.get("goods_id")))) {
                        throw new InquiryException("-2", String.format("选择的商品%s已匹配到该询价商品,不能重复添加! ", vendorGoodsMatchedQuotationMap.get("goods_id")));
                    }
                });
            } catch (InquiryException e) {
                return SingleResponse.error(e.getErrCode(), e.getErrMsg());
            }
        }
        // 获取商品信息
        SingleResponse<BOList> goodsBOList = BoServiceUtils.findListByIn(ModelConst.T_GOODSES, "id", inquiryGoodsDto.getGoodsIdList());
        log.info("------------------------goodsBOList：{}------------------------", JSONObject.toJSONString(goodsBOList));
        Collection<Map<String, Object>> goodsCollection = goodsBOList.getData().getData();
        // 获取询价商品信息
        SingleResponse<BOList> inquiryGoodsBOList = BoServiceUtils.findListBySimple(ModelConst.T_INQUIRY_GOODS, "id", vendorGoodsMatchedInquiryGoodsId);
        log.info("------------------------inquiryGoodsBOList：{}------------------------", JSONObject.toJSONString(inquiryGoodsBOList));
        CreateInquiryGoodsDto inquiryGoods = JSON.parseObject(JSON.toJSONString(inquiryGoodsBOList.getData().getData().get(0)), CreateInquiryGoodsDto.class);
        // 保存预报价列表
        Set<VendorGoodsMatchedQuotation> quotationGoodsSet = reBuildVendorGoodsMatchedQuotation(inquiryGoods, goodsCollection, vendorGoodsMatchedInquiryGoodsId);
        List<Map<String, Object>> vendorGoodsMatchedQuotationList = Lists.newArrayList();
        for (VendorGoodsMatchedQuotation quotation : quotationGoodsSet) {
            Map<String, Object> quotationMap = BeanUtils.bean2Map(quotation);
            vendorGoodsMatchedQuotationList.add(quotationMap);
        }
        SingleResponse<BO> vendorGoodsMatchedQuotationResult = BoServiceUtils.createBo(ModelConst.T_VENDOR_MATCHED_QUOTATION, vendorGoodsMatchedQuotationList);
        log.info("------------------------vendorGoodsMatchedQuotationResult：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationResult));
        return vendorGoodsMatchedQuotationResult;
    }

    /**
     * 提交匹配商品
     *
     * @param vendorGoodsMatchedInquiryGoods 平台报价询价列表
     * @return 响应结果
     */
    @Path("submitMatch")
    @POST
    @Operation(summary = "提交匹配商品", tags = CUSTOM_SERVICE)
    public SingleResponse<BO> submitMatch(@Parameter VendorGoodsMatchedInquiryGoods vendorGoodsMatchedInquiryGoods) {
        if (vendorGoodsMatchedInquiryGoods.getVendorGoodsMatchingQuotations() == null || vendorGoodsMatchedInquiryGoods.getVendorGoodsMatchingQuotations().isEmpty()) {
            return SingleResponse.error("-1", "请添加匹配的商品");
        }

        Map<String, Object> vendorGoodsMatchedInquiryGoodsMap = BeanUtils.bean2Map(vendorGoodsMatchedInquiryGoods);
        vendorGoodsMatchedInquiryGoodsMap.put("attachment", vendorGoodsMatchedInquiryGoods.getAttachment());
        SingleResponse<BO> vendorGoodsMatchedInquiryGoodsResult = BoServiceUtils.createBo(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, Collections.singletonList(vendorGoodsMatchedInquiryGoodsMap));
        log.info("------------------------vendorGoodsMatchedInquiryGoodsResult：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsResult));

        List<Map<String, Object>> vendorGoodsMatchedQuotationList = Lists.newArrayList();
        for (VendorGoodsMatchedQuotation quotation : vendorGoodsMatchedInquiryGoods.getVendorGoodsMatchingQuotations()) {
            Map<String, Object> quotationMap = BeanUtils.bean2Map(quotation);
            vendorGoodsMatchedQuotationList.add(quotationMap);
        }
        SingleResponse<BO> vendorGoodsMatchedQuotationResult = BoServiceUtils.createBo(ModelConst.T_VENDOR_MATCHED_QUOTATION, vendorGoodsMatchedQuotationList);
        log.info("------------------------vendorGoodsMatchedQuotationResult：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationResult));

        Map<String, Object> inquiryGoodsMap = Maps.newHashMap();
        inquiryGoodsMap.put("id", vendorGoodsMatchedInquiryGoods.getInquiry_goods_id());
        inquiryGoodsMap.put("pass", "1");
        inquiryGoodsMap.put("is_matching", true);
        SingleResponse<BO> inquiryGoodsResult = BoServiceUtils.updateMainBo(ModelConst.T_INQUIRY_GOODS, inquiryGoodsMap);
        log.info("------------------------inquiryGoodsResult：{}------------------------", JSONObject.toJSONString(inquiryGoodsResult));
        return vendorGoodsMatchedInquiryGoodsResult;
    }

    /**
     * 获取快速报价列表
     *
     * @param vendorGoodsMatchedDto 请求参数
     * @return 响应结果
     */
    @Path("getQuickQuotationList")
    @POST
    @Operation(summary = "获取快速报价列表", tags = CUSTOM_SERVICE)
    public SingleResponse<BOList> getQuickQuotationList(@Parameter VendorGoodsMatchedDto vendorGoodsMatchedDto) {
        if (vendorGoodsMatchedDto.getInquiryGoodsIdList() == null || vendorGoodsMatchedDto.getInquiryGoodsIdList().isEmpty()) {
            return SingleResponse.error("-1", "询价商品id不能为空");
        }
        // 获取快速报价列表
        SingleResponse<BOList> quickQuotationBOList = BoServiceUtils.findListByIn(ModelConst.T_VENDOR_MATCHED_QUOTATION, "vendor_matched_inq_goods_id", vendorGoodsMatchedDto.getInquiryGoodsIdList());
        if (!quickQuotationBOList.isSuccess()) {
            return SingleResponse.error("-2", "获取快速报价列表失败，请检查网络设置");
        }
        log.info("------------------------quickQuotationBOList：{}------------------------", JSONObject.toJSONString(quickQuotationBOList));
        return quickQuotationBOList;
    }

    /**
     * 移除已匹配的平台报价数据
     *
     * @param vendorGoodsMatchedDto 请求参数
     * @return 响应结果
     */
    @Path("remove")
    @POST
    @Operation(summary = "移除已匹配的平台报价数据", tags = CUSTOM_SERVICE)
    public SingleResponse<BO> remove(@Parameter VendorGoodsMatchedDto vendorGoodsMatchedDto) {
        if (vendorGoodsMatchedDto.getInquiryGoodsIdList() == null || vendorGoodsMatchedDto.getInquiryGoodsIdList().isEmpty()) {
            return SingleResponse.error("-1", "询价商品id不能为空");
        }
        // 1，删除供应商匹配商品
        SingleResponse<BOList> vendorGoodsMatchedInquiryGoodsBOList = BoServiceUtils.findListByIn(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, "inquiry_goods_id", vendorGoodsMatchedDto.getInquiryGoodsIdList());
        log.info("------------------------vendorGoodsMatchedInquiryGoodsBOList：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsBOList));
        List<String> vendorGoodsMatchedInquiryGoodsIdList = Lists.newArrayList();
        vendorGoodsMatchedInquiryGoodsBOList.getData().getData().forEach(vendorGoodsMatchedInquiryGoods ->
                vendorGoodsMatchedInquiryGoodsIdList.add(vendorGoodsMatchedInquiryGoods.get("id").toString()));
        // 删除平台报价询价商品
        StringBuilder deleteSql = new StringBuilder();
        Map<String, Object> param = Maps.newHashMap();
        deleteSql.append("delete from\n");
        deleteSql.append(JdbcTemplateUtils.getTableName(ModelConst.T_VENDOR_MATCHED_INQ_GOODS)).append("\n");
        deleteSql.append("where id in (:ids)");
        param.put("ids", vendorGoodsMatchedInquiryGoodsIdList);
        log.info("sql = {}, parameters = {}", deleteSql, JSONObject.toJSONString(param));
        jdbcTemplate.update(deleteSql.toString(), param);
        // 2，删除平台报价商品
        deleteVendorGoodsMatchedQuotation(vendorGoodsMatchedInquiryGoodsIdList);
        // 3，修改询价商品
        List<Map<String, Object>> inquiryGoodsList = Lists.newArrayList();
        vendorGoodsMatchedDto.getInquiryGoodsIdList().forEach(inquiryGoodsId -> {
            Map<String, Object> inquiryGoodsMap = Maps.newHashMap();
            inquiryGoodsMap.put("id", inquiryGoodsId);
            inquiryGoodsMap.put("pass", "0");
            // 修改状态为未匹配，在进行中的询价商品中可以重新匹配
            inquiryGoodsMap.put("is_matching", false);
            inquiryGoodsMap.put("reason", vendorGoodsMatchedDto.getReason());
            inquiryGoodsList.add(inquiryGoodsMap);
        });
        SingleResponse<BO> inquiryGoodsUpdateResult = BoServiceUtils.updateMainBo(ModelConst.T_INQUIRY_GOODS, inquiryGoodsList);
        log.info("------------------------inquiryGoodsUpdateResult：{}------------------------", JSONObject.toJSONString(inquiryGoodsUpdateResult));
        return inquiryGoodsUpdateResult;
    }

    /**
     * 重新匹配
     *
     * @param vendorGoodsMatchedDto 请求参数
     * @return 响应结果
     */
    @Path("reMatching")
    @POST
    @Operation(summary = "重新匹配", tags = CUSTOM_SERVICE)
    public SingleResponse<?> reMatching(@Parameter VendorGoodsMatchedDto vendorGoodsMatchedDto) {
        if (vendorGoodsMatchedDto.getInquiryGoodsIdList() == null || vendorGoodsMatchedDto.getInquiryGoodsIdList().isEmpty()) {
            return SingleResponse.error("-1", "询价商品id不能为空");
        }
        // 通过询价商品单号获取询价单信息
        SingleResponse<BOList> inquiryGoodsBOList = BoServiceUtils.findListByIn(ModelConst.T_INQUIRY_GOODS, "id", vendorGoodsMatchedDto.getInquiryGoodsIdList());
        List<CreateInquiryGoodsDto> inquiryGoodsList = JSONUtil.toList(JSONUtil.parseArray(inquiryGoodsBOList.getData().getData()), CreateInquiryGoodsDto.class);
        // 获取平台报价询价商品信息
        SingleResponse<BOList> vendorGoodsMatchedInquiryGoodsBOList = BoServiceUtils.findListByIn(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, "inquiry_goods_id", vendorGoodsMatchedDto.getInquiryGoodsIdList());
        Map<String, Boolean> statusMap = null;
        if (vendorGoodsMatchedInquiryGoodsBOList.getData().getTotal() > 0) {
            List<VendorGoodsMatchedInquiryGoods> vendorGoodsMatchedInquiryGoodsList = JSONUtil.toList(JSONUtil.parseArray(vendorGoodsMatchedInquiryGoodsBOList.getData().getData()), VendorGoodsMatchedInquiryGoods.class);
            for (VendorGoodsMatchedInquiryGoods vendorGoodsMatchedInquiryGoods : vendorGoodsMatchedInquiryGoodsList) {
                statusMap = Maps.newHashMap();
                if (vendorGoodsMatchedInquiryGoods.getIs_quoted()) {
                    return SingleResponse.error("-2", String.format("询价商品%s已报价, 不能重新匹配!", vendorGoodsMatchedInquiryGoods.getInquiry_goods_id()));
                }
                // 移除已匹配的报价
                deleteVendorGoodsMatchedQuotation(Collections.singletonList(vendorGoodsMatchedInquiryGoods.getId()));
                statusMap.put(vendorGoodsMatchedInquiryGoods.getId(), vendorGoodsMatchedInquiryGoods.getIs_auto_matching());
            }
        }
        // 生成平台报价记录
        generateQuotationListByInquiryGoods(inquiryGoodsList, statusMap, false);
        return SingleResponse.buildSuccess();
    }

    /**
     * 发布报价
     *
     * @param vendorGoodsMatchedQuotationList 匹配报价商品
     * @return 响应结果
     */
    @Path("publishQuotation")
    @POST
    @Operation(summary = "发布报价", tags = CUSTOM_SERVICE)
    public SingleResponse<BO> publishQuotation(@Parameter List<VendorGoodsMatchedQuotation> vendorGoodsMatchedQuotationList) {
        if (vendorGoodsMatchedQuotationList == null || vendorGoodsMatchedQuotationList.isEmpty()) {
            return SingleResponse.error("-1", "未获取到报价商品，请检查");
        }
        vendorGoodsMatchedQuotationList = vendorGoodsMatchedQuotationList.stream().filter(quotation -> !StringUtils.isEmpty(quotation.getInquiry_goods_id()))
                .collect(Collectors.toList());
        try {
            Set<String> inquiryGoodsIdSet = vendorGoodsMatchedQuotationList.stream().map(quotation -> {
                List<SelectorFormat> vendorIdList = quotation.getVendor_id();
                if (vendorIdList == null || vendorIdList.isEmpty()) {
                    throw new InquiryException("-2", "供应商id参数为空，请联系管理员！");
                }
                if (StringUtils.isEmpty(quotation.getGoods_id())) {
                    List<Map<String, Object>> goodsList = listGoods(Collections.singletonList(quotation.getGoods_id()), null, new Date());
                    if (CollectionUtils.isEmpty(goodsList)) {
                        throw new InquiryException("-3", String.format("%s的供应商商品%s不存在, 可能被删除, 禁用, 下架或过期, 请检查！", quotation.getInquiry_goods_id(), quotation.getGoods_id()));
                    }
                    quotation.setClient_vendor_goods_id(String.valueOf(goodsList.get(0).get("client_goods_id")));
                }
                return quotation.getInquiry_goods_id() + '-' + vendorIdList.get(0);
            }).collect(Collectors.toSet());
            if (inquiryGoodsIdSet.size() != vendorGoodsMatchedQuotationList.size()) {
                throw new InquiryException("-4", "一个供应商仅能对一条询价商品报价一次，请检查！");
            }
        } catch (InquiryException e) {
            e.printStackTrace();
            return SingleResponse.error(e.getErrCode(), e.getErrMsg());
        }
        Set<String> inquiryGoodsIdSet = Sets.newHashSet();
        try {
            vendorGoodsMatchedQuotationList.forEach(quotation -> {
                // 批量参与询价商品
                InquiryGoodsDto inquiryGoodsDto = new InquiryGoodsDto();
                inquiryGoodsDto.setInquiryGoodsIdList(Collections.singletonList(quotation.getInquiry_goods_id()));
                // 设置参与的供应商id
                String orgId = quotation.getVendor_id().get(0).getId();
                inquiryGoodsDto.setOrgId(orgId);
                inquiryGoodsDto.setIsVirtual(false);
                SingleResponse<List<BO>> quotationGoodsResult = quotationService.batchParticipation(inquiryGoodsDto);
                log.info("------------------------quotationGoodsResult：{}------------------------", JSONObject.toJSONString(quotationGoodsResult));
                if (!quotationGoodsResult.isSuccess()) {
                    throw new InquiryException("-5", "批量参与失败：" + quotation.getInquiry_goods_id() + " 返回：" + JSONObject.toJSONString(quotationGoodsResult) + "");
                }
                Map<String, Object> quotationMap = quotationGoodsResult.getData().get(0).getData();
                quotationMap.put("client_vendor_goods_id", quotation.getClient_vendor_goods_id());
                quotationMap.put("source", QuotationSourceEnum.PmQuotation.name());
                quotationMap.put("auto_quotation", true);
                // 重新构建报价商品
                BigDecimal pretaxAmount = BigDecimalUtils.div(quotation.getAmount(), quotation.getTax_rate().add(BigDecimal.ONE), 2);
                quotationMap.put("pretax_amount", pretaxAmount);// 更新税前总价
                quotationMap.put("tax_payable", BigDecimalUtils.sub(quotation.getAmount(), pretaxAmount));// 更新税额
                quotationMap.put("pretax_price", BigDecimalUtils.div(pretaxAmount, quotation.getNum(), 2));// 更新税前单价
                quotationMap.put("freight", BigDecimal.ZERO);// 运费分摊至商品单价并清空运费
                quotationMap.put("tax_rate_freight", String.valueOf(BigDecimal.ZERO));// 更新运费税率
                quotationMap.put("tax_payable_freight", BigDecimal.ZERO);// 更新运费税额
                quotationMap.put("pretax_freight", BigDecimal.ZERO);// 更新税前运费
                quotationMap.put("tax_rate", String.valueOf(quotation.getTax_rate()));
                // FIXME 先暂时这么处理，防止报错。之后优化
                quotationMap.put("expire", quotation.getExpiry());
                quotationMap.put("address", quotation.getDelivery_place());
                quotationMap.put("min_order", quotation.getMin_order());
                quotationMap.put("maximum", BigDecimal.ZERO);

                // 附件是字符串，需要转成List<Attachment>
                Object attachment = quotationMap.get("attachment");
                if ("[]".equals(String.valueOf(attachment))) {
                    quotationMap.put("attachment", Lists.newArrayList());
                } else {
                    quotationMap.put("attachment", JSONObject.parseArray(String.valueOf(attachment), AttachmentFormat.class));
                }
                // 更新报价时不需要用到的字段，remove掉
                quotationMap.put("clarify_attachment", Lists.newArrayList());
                quotationMap.remove("member_id");
                quotationMap.remove("platform_quotation_id");
                quotationMap.remove("vendor_department_id");
                quotationMap.remove("vendor_organization_id");
                quotationMap.remove("operator");
                quotationMap.remove("approval_by");

                QuotationGoods quotationGoods = JSON.parseObject(JSON.toJSONString(quotationMap), QuotationGoods.class);
                SingleResponse<List<BO>> quotationGoodsUpdate = quotationService.updateQuotation(Collections.singletonList(quotationGoods));
                log.info("------------------------quotationGoodsUpdate：{}------------------------", JSONObject.toJSONString(quotationGoodsUpdate));
                // 提交报价商品，整单报价不会进入平台报价
                QuotationGoodsDto quotationGoodsDto = new QuotationGoodsDto();
                quotationGoodsDto.setQuotationId(String.valueOf(quotationMap.get("id")));
                quotationGoodsDto.setInquiryId(String.valueOf(quotationMap.get("inquiry_id")));
                SingleResponse<BO> quotationGoodsSubmit = quotationService.batchCommit(Collections.singletonList(quotationGoodsDto));
                log.info("------------------------quotationGoodsSubmit：{}------------------------", JSONObject.toJSONString(quotationGoodsSubmit));
                inquiryGoodsIdSet.add(quotation.getInquiry_goods_id());
            });
        } catch (InquiryException e) {
            e.printStackTrace();
            return SingleResponse.error(e.getErrCode(), e.getErrMsg());
        }
        SingleResponse<BO> vendorGoodsMatchedInquiryGoodsUpdate = new SingleResponse<>();
        // 修改平台报价匹配列表的数据
        if (!inquiryGoodsIdSet.isEmpty()) {
            SingleResponse<BOList> vendorGoodsMatchedQuotationBOList = BoServiceUtils.findListByIn(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, "inquiry_goods_id", inquiryGoodsIdSet);
            log.info("------------------------vendorGoodsMatchedQuotationBOList：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationBOList));
            if (vendorGoodsMatchedQuotationBOList.isSuccess() && vendorGoodsMatchedQuotationBOList.getData().getTotal() > 0) {
                List<Map<String, Object>> vendorGoodsMatchedQuotationDataList = Lists.newArrayList();
                vendorGoodsMatchedQuotationBOList.getData().getData().forEach(vendorGoodsMatchedQuotation -> {
                    Map<String, Object> vendorGoodsMatchedQuotationDataMap = Maps.newHashMap();
                    vendorGoodsMatchedQuotationDataMap.put("id", vendorGoodsMatchedQuotation.get("id"));
                    vendorGoodsMatchedQuotationDataMap.put("is_quoted", true);
                    vendorGoodsMatchedQuotationDataList.add(vendorGoodsMatchedQuotationDataMap);
                });
                vendorGoodsMatchedInquiryGoodsUpdate = BoServiceUtils.updateMainBo(ModelConst.T_VENDOR_MATCHED_INQ_GOODS, vendorGoodsMatchedQuotationDataList);
                log.info("------------------------vendorGoodsMatchedInquiryGoodsUpdate：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoodsUpdate));
            } else {
                vendorGoodsMatchedInquiryGoodsUpdate.setSuccess(true);
            }
        } else {
            vendorGoodsMatchedInquiryGoodsUpdate.setSuccess(true);
        }
        return vendorGoodsMatchedInquiryGoodsUpdate;
    }

    /**
     * 删除平台报价商品
     *
     * @param vendorGoodsMatchedInquiryGoodsIdList 询价id
     */
    private void deleteVendorGoodsMatchedQuotation(List<String> vendorGoodsMatchedInquiryGoodsIdList) {
        SingleResponse<BOList> vendorGoodsMatchedQuotationBOList = BoServiceUtils.findListByIn(ModelConst.T_VENDOR_MATCHED_QUOTATION, "vendor_matched_inq_goods_id", vendorGoodsMatchedInquiryGoodsIdList);
        log.info("------------------------vendorGoodsMatchedQuotationBOList：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedQuotationBOList));
        List<String> vendorGoodsMatchedQuotationIdList = Lists.newArrayList();
        vendorGoodsMatchedQuotationBOList.getData().getData().forEach(vendorGoodsMatchedQuotation ->
                vendorGoodsMatchedQuotationIdList.add(vendorGoodsMatchedQuotation.get("id").toString()));
        StringBuilder deleteSql = new StringBuilder();
        Map<String, Object> param = Maps.newHashMap();
        deleteSql.append("delete from\n");
        deleteSql.append(JdbcTemplateUtils.getTableName(ModelConst.T_VENDOR_MATCHED_QUOTATION)).append("\n");
        deleteSql.append("where id in (:ids)");
        param.put("ids", vendorGoodsMatchedQuotationIdList);
        log.info("sql = {}, parameters = {}", deleteSql, JSONObject.toJSONString(param));
        jdbcTemplate.update(deleteSql.toString(), param);
    }

    /**
     * 构建询价商品报价匹配
     *
     * @param inquiryGoods    询价商品
     * @param goodsCollection 供应商商品
     * @return 平台报价询价商品
     */
    private VendorGoodsMatchedInquiryGoods buildVendorGoodsMatchedInquiry(CreateInquiryGoodsDto inquiryGoods, Collection<Map<String, Object>> goodsCollection) {
        VendorGoodsMatchedInquiryGoods vendorGoodsMatchedInquiryGoods = formatByInquiryGoods(inquiryGoods);
        log.info("------------------------vendorGoodsMatchedInquiryGoods：{}------------------------", JSONObject.toJSONString(vendorGoodsMatchedInquiryGoods));
        vendorGoodsMatchedInquiryGoods.setIs_auto_matching(false);
        if (!goodsCollection.isEmpty()) {
            Set<VendorGoodsMatchedQuotation> quotationGoodsSet = reBuildVendorGoodsMatchedQuotation(inquiryGoods, goodsCollection, vendorGoodsMatchedInquiryGoods.getId());
            log.info("------------------------quotationGoodsSet：{}------------------------", JSONObject.toJSONString(quotationGoodsSet));
            vendorGoodsMatchedInquiryGoods.setVendorGoodsMatchingQuotations(quotationGoodsSet);
        }
        return vendorGoodsMatchedInquiryGoods;
    }

    /**
     * 平台预报价列表
     *
     * @param inquiryGoods                       询价商品
     * @param goodsCollection                    供应商商品
     * @param vendorGoodsMatchedInquiryGoodsId   平台报价询价商品id
     * @return 预报价列表
     */
    private Set<VendorGoodsMatchedQuotation> reBuildVendorGoodsMatchedQuotation(CreateInquiryGoodsDto inquiryGoods, Collection<Map<String, Object>> goodsCollection, String vendorGoodsMatchedInquiryGoodsId) {
        // 对查出来的商品进行转换到供应商匹配商品对象中
        Set<VendorGoodsMatchedQuotation> quotationGoodsSet = formatByGoods(goodsCollection);
        quotationGoodsSet.forEach(quotation -> {
            // todo 运费比例
            OrganizationDto org = OrgUtils.getOrgByOrgId(quotation.getVendor_id().get(0).getId());
            quotation.setFreight_rate(org.getFreight_ratio());
            // todo 账期
            Integer accountPeriod = inquiryGoods.getAccount_period();
            if (accountPeriod == null) {
                accountPeriod = 0;
            }
            // todo 平台费比例
            quotation.setPlatform_rate(BigDecimal.ZERO);

            // todo 服务费比例
            quotation.setService_rate(BigDecimal.ZERO);

            quotation.setId(SchemaHelper.getId());
            quotation.setInquiry_id(inquiryGoods.getInquiry_id());
            quotation.setInquiry_goods_name(inquiryGoods.getName());
            quotation.setNum(inquiryGoods.getNum());
            quotation.setInquiry_goods_id(inquiryGoods.getId());
            quotation.setFreight(BigDecimal.ZERO);
            quotation.setAmount(BigDecimalUtils.mul(quotation.getNum(), quotation.getPrice()));
            quotation.setVendor_matched_inq_goods_id(vendorGoodsMatchedInquiryGoodsId);
            log.info("------------------------平台报价报价商品数据：{}------------------------", JSONObject.toJSONString(quotation));
        });
        return quotationGoodsSet;
    }

    /**
     * 根据供应商商品对象赋值
     *
     * @param goodsCollection 供应商商品
     * @return 预报价列表
     */
    @SuppressWarnings("unchecked")
    private Set<VendorGoodsMatchedQuotation> formatByGoods(Collection<Map<String, Object>> goodsCollection) {
        Set<VendorGoodsMatchedQuotation> quotationGoodsSet = Sets.newHashSet();
        goodsCollection.forEach(goods -> {
            VendorGoodsMatchedQuotation quotation = new VendorGoodsMatchedQuotation();
            quotation.setVendor_id((List<SelectorFormat>) goods.get("vendor_id"));
            quotation.setExpiry(String.valueOf(goods.get("expiry")));
            quotation.setImages((List<AttachmentFormat>)goods.get("images"));
            quotation.setAttachment(goods.get("attachment") == null ? Lists.newArrayList() : (List<AttachmentFormat>)goods.get("attachment"));
            quotation.setGoods_id(goods.get("id").toString());
            quotation.setVendor_name(Optional.ofNullable((String) goods.get("org_fullname")).orElse(""));
            quotation.setCatalog(Optional.ofNullable((String) goods.get("catalog")).orElse(""));
            quotation.setUnit(Optional.ofNullable((String) goods.get("unit")).orElse(""));
            quotation.setPackage_unit(Optional.ofNullable((String) goods.get("package_unit")).orElse(""));
            quotation.setPackage_num(Optional.ofNullable((BigDecimal) goods.get("package_num")).orElse(BigDecimal.ZERO));
            quotation.setPretax_price(Optional.ofNullable((BigDecimal) goods.get("pretax_price")).orElse(BigDecimal.ZERO));
            quotation.setPrice(Optional.ofNullable((BigDecimal) goods.get("price")).orElse(BigDecimal.ZERO));
            quotation.setTax_rate(Optional.ofNullable((BigDecimal) goods.get("tax_rate")).orElse(BigDecimal.ZERO));
            quotation.setSku(Optional.ofNullable((String) goods.get("sku")).orElse(""));
            quotation.setStock(Optional.ofNullable((BigDecimal) goods.get("stock")).orElse(BigDecimal.ZERO));
            quotation.setWarranty(Optional.ofNullable((String) goods.get("warranty")).orElse(""));
            quotation.setDelivery(Optional.ofNullable((String) goods.get("delivery")).orElse(null));
            quotation.setMin_order(Optional.ofNullable((BigDecimal) goods.get("min_order")).orElse(BigDecimal.ZERO));
            quotation.setLength(Optional.ofNullable((BigDecimal) goods.get("length")).orElse(BigDecimal.ZERO));
            quotation.setWidth(Optional.ofNullable((BigDecimal) goods.get("width")).orElse(BigDecimal.ZERO));
            quotation.setHeight(Optional.ofNullable((BigDecimal) goods.get("height")).orElse(BigDecimal.ZERO));
            quotation.setWeight(Optional.ofNullable((BigDecimal) goods.get("weight")).orElse(BigDecimal.ZERO));
            quotation.setFreight_template_id(Optional.ofNullable((String) goods.get("freight_template_id")).orElse(""));
            quotation.setSaled("1".equals(String.valueOf(goods.get("saled"))));
            quotation.setEnabled("1".equals(String.valueOf(goods.get("enabled"))));
            quotation.setDelivery_claim(Optional.ofNullable((String) goods.get("delivery_claim")).orElse(""));
            quotation.setCategory(Optional.ofNullable((String) goods.get("category")).orElse(""));
            quotation.setBrand(Optional.ofNullable((String) goods.get("brand")).orElse(""));
            quotation.setName(Optional.ofNullable((String) goods.get("name")).orElse(""));
            quotation.setModel(Optional.ofNullable((String) goods.get("model")).orElse(""));
            quotation.setSpec(Optional.ofNullable((String) goods.get("spec")).orElse(""));
            quotation.setSku(Optional.ofNullable((String) goods.get("sku")).orElse(""));
            quotation.setGolden_tax(Optional.ofNullable((String) goods.get("golden_tax")).orElse(""));
            quotation.setBar_code(Optional.ofNullable((String) goods.get("bar_code")).orElse(""));
            quotation.setUnspsc(Optional.ofNullable((String) goods.get("unspsc")).orElse(""));
            quotation.setDescription(Optional.ofNullable((String) goods.get("description")).orElse(""));
            quotation.setDelivery_place(Optional.ofNullable((String) goods.get("delivery_place")).orElse(""));
            quotation.setTechnical(Optional.ofNullable((String) goods.get("technical")).orElse(""));
            quotation.setPackaging(Optional.ofNullable((String) goods.get("packaging")).orElse(""));
            quotation.setMemo(Optional.ofNullable((String) goods.get("memo")).orElse(""));
            quotationGoodsSet.add(quotation);
        });
        return quotationGoodsSet;
    }

    /**
     * 获取询价单信息
     *
     * @param inquiryGoods 询价商品
     * @return 供应商商品
     */
    private Collection<Map<String, Object>> getGoodsCollection(CreateInquiryGoodsDto inquiryGoods) {
        // 获取商品型号
        String model = inquiryGoods.getModel();
        // 获取询价单报价有效期
        SingleResponse<BOList> inquiryResult = BoServiceUtils.findListBySimple(ModelConst.T_INQUIRY, "id", inquiryGoods.getInquiry_id());
        Date quoteMinTimeStrategy = DateUtils.parseDate(inquiryResult.getData().getData().get(0).get("quote_min_time_strategy").toString(), "yyyy-MM-dd HH:mm:ss");
        List<Map<String, Object>> goodsList = listGoods(null, model, quoteMinTimeStrategy);
        log.info("询价型号{}，在供应商商品库中检索到{}条数据。", model, goodsList.size());
        return goodsList;
    }

    /**
     * 根据条件获取商品列表
     *
     * @param goodsIdList          商品id列表
     * @param model                型号
     * @param quoteMinTimeStrategy 报价有效期
     * @return 商品列表
     */
    private List<Map<String, Object>> listGoods(Collection<String> goodsIdList, String model, Date quoteMinTimeStrategy) {
        JdbcTemplateUtils sqlBuilder = Objects.requireNonNull(JdbcTemplateUtils.builder(AppConst.COMMODITYMATERIALS, ModelConst.T_GOODSES).selectField("*"));
        if (!CollectionUtils.isEmpty(goodsIdList)) {
            sqlBuilder.in("id", goodsIdList);
        }
        if (!StringUtils.isEmpty(model)) {
            sqlBuilder.like("model", model);
        }
        sqlBuilder.eq("enabled", "1");
        //设置只匹配虚拟供应商商品 不匹配客户商品
        sqlBuilder.in("type", Arrays.asList(GoodsType.Mall.ordinal(), GoodsType.Virtual.ordinal()));
        sqlBuilder.gte("expiry", quoteMinTimeStrategy);
        List<Map<String, Object>> goodsList = sqlBuilder.queryForList();
        BoResultFormat.resultFormat(goodsList, ModelConst.T_GOODSES, true);
        log.info("------------------------goodsList：{}------------------------", JSONObject.toJSONString(goodsList));
        return goodsList;
    }

    /**
     * 根据询价商品对象赋值
     *
     * @param inquiryGoods 询价商品
     * @return 平台报价询价商品
     */
    private VendorGoodsMatchedInquiryGoods formatByInquiryGoods(CreateInquiryGoodsDto inquiryGoods) {
        // 根据询价商品获取询价单信息
        SingleResponse<BOList> inquiryResult = BoServiceUtils.findListBySimple(ModelConst.T_INQUIRY, "id", inquiryGoods.getInquiry_id());
        log.info("------------------------inquiryResult：{}------------------------", JSONObject.toJSONString(inquiryResult));
        CreateInquiryDto inquiry = JSON.parseObject(JSON.toJSONString(inquiryResult.getData().getData().get(0)), CreateInquiryDto.class);

        VendorGoodsMatchedInquiryGoods goodsIndex = new VendorGoodsMatchedInquiryGoods();
        goodsIndex.setId(inquiryGoods.getId());
        goodsIndex.setInquiry_goods_id(inquiryGoods.getId());
        goodsIndex.setInquiry_id(inquiryGoods.getInquiry_id());
        goodsIndex.setDemand_goods_id(inquiryGoods.getDemand_goods_id());
        goodsIndex.setClient_id(Optional.ofNullable(inquiryGoods.getClient_id()).orElse(""));
        goodsIndex.setClient_inquiry_goods_id(Optional.ofNullable(inquiryGoods.getClient_inquiry_goods_id()).orElse(""));
        goodsIndex.setInquiry_goods_status(inquiryGoods.getInquiry_goods_status());
        goodsIndex.setPlatform_category_name(inquiryGoods.getPlatform_category_name());
        goodsIndex.setOrg_category_name(inquiryGoods.getOrg_category_name());
        goodsIndex.setSku(Optional.ofNullable(inquiryGoods.getSku()).orElse(""));
        goodsIndex.setBar_code(Optional.ofNullable(inquiryGoods.getBar_code()).orElse(""));
        goodsIndex.setName(inquiryGoods.getName());
        goodsIndex.setBrand(inquiryGoods.getBrand());
        goodsIndex.setExpire(inquiry.getExpire());
        goodsIndex.setModel(inquiryGoods.getModel());
        goodsIndex.setSpec(inquiryGoods.getSpec());
        goodsIndex.setAddress(inquiryGoods.getAddress());
        goodsIndex.setDelivery(inquiryGoods.getDelivery());
        goodsIndex.setNum(inquiryGoods.getNum());
        goodsIndex.setUnit(inquiryGoods.getUnit());
        goodsIndex.setPackage_num(Optional.ofNullable(inquiryGoods.getPackage_num()).orElse(BigDecimal.ZERO));
        goodsIndex.setQuote_count(Optional.ofNullable(inquiryGoods.getQuote_count()).orElse(0));
        goodsIndex.setPartake_count(Optional.ofNullable(inquiryGoods.getPartake_count()).orElse(0));
        // 设置已报价为false
        goodsIndex.setIs_quoted(false);
        goodsIndex.setItem_type(Optional.ofNullable(inquiryGoods.getItem_type()).orElse(false));
        goodsIndex.setQuote_max_price_limit(Optional.ofNullable(inquiryGoods.getQuote_max_price_limit()).orElse(BigDecimal.ZERO));
        goodsIndex.setQuote_edit_limit(Optional.ofNullable(inquiryGoods.getQuote_edit_limit()).orElse(false));
        goodsIndex.setAttachment(Optional.ofNullable(inquiryGoods.getAttachment()).orElse(Lists.newArrayList()));
        goodsIndex.setUrl(inquiryGoods.getUrl());
        goodsIndex.setMemo(inquiryGoods.getMemo());
        goodsIndex.setDescription(inquiryGoods.getDescription());
        goodsIndex.setSafety_stock_num(Optional.ofNullable(inquiryGoods.getSafety_stock_num()).orElse(BigDecimal.ZERO));
        goodsIndex.setMember_name(Optional.ofNullable(inquiry.getMember_name()).orElse(""));
        goodsIndex.setDepartment_name(Optional.ofNullable(inquiry.getDepartment_name()).orElse(""));
        goodsIndex.setOrganization_company_name(Optional.ofNullable(inquiry.getOrganization_company_name()).orElse(""));
        log.info("------------------------平台报价询价商品数据：{}------------------------", JSONObject.toJSONString(goodsIndex));
        return goodsIndex;
    }
}
